<!--
* description: 总部内部领用-内部领用单查询
* author: hezm
* createdDate: 2021-2-23
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-is-show-more-btn="true"
      :dynamic-api-style="'restful'"
    />
    <detailList
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :dynamic-api-style="'restful'"
      :edit-row-data="editRowData"
      @close="close"
    />
  </div>
</template>

<script>
import { formMixins } from '@/components/mixins/formMixins'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/paSparePartsManagement'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: 'InternalCheckQuery',
  components: {
    OneTableTemplate,
    DetailList: () => import('./detailList')
  },
  mixins: [oneTableWithViewTemplateMixins, formMixins],
  data() {
    return {
      editRowData: {},
      dynamicApiConfigs: orgApis.internalCheckQuery,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'controlBtn',
              label: '操作', // 操作
              codeField: 'controlBtn',
              width: 100,
              align: 'center',
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '查看明细', // 编辑
                  align: 'center',
                  codeField: 'editControlBtn',
                  clickEvent: (index) => {
                    this.edit(index)
                  },
                  component: () => import('@/components/org/linkButton')
                }
              ]
            },
            {
              prop: 'requisitionCode',
              label: '领用单号',
              align: 'center'
            },
            {
              prop: 'warehouseName',
              label: '领用仓库',
              align: 'center'
            },
            {
              prop: 'requisitionStatusCn',
              label: '单据状态',
              align: 'center'
            },
            {
              prop: 'deptName',
              label: '领用部门',
              align: 'center'
            },
            {
              prop: 'empName',
              label: '领用人',
              align: 'center'
            },
            {
              prop: 'requisitionVariety',
              label: '品种数',
              align: 'center'
            },
            {
              prop: 'requisitionUse',
              label: '领用用途',
              align: 'center'
            },
            {
              prop: 'receiver',
              label: '收货人',
              align: 'center'
            },
            {
              prop: 'receiverPhone',
              label: '联系电话',
              align: 'center'
            },
            {
              prop: 'receiverAddress',
              label: '收货地址',
              align: 'center'
            }
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              prop: 'controlBtn',
              label: '操作', // 操作
              codeField: 'controlBtn',
              width: 100,
              align: 'center',
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '查看明细', // 编辑
                  align: 'center',
                  codeField: 'editControlBtn',
                  clickEvent: (index) => {
                    this.edit(index)
                  },
                  component: () => import('@/components/org/linkButton')
                }
              ]
            },
            // 库存状态
            {
              compKey: 'compKey1',
              labelName: '领用单号：',
              codeField: 'requisitionCode',
              component: () => import('@/components/org/commonInput'),
              oFields: 'AsId,AsText',
              type: 'inputText',
              isMust: true,
              span: 6
            },
            // 车辆状态
            {
              compKey: 'compKey2',
              labelName: '领用仓库：',
              codeField: 'warehouseId',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: orgApis.findWarehouseInfo,
                defOptionFields: ['warehouseId', 'warehouseName']
              },
              type: 'dropdownList',
              type: 'inputText',
              isMust: true,
              span: 6
            },
            // 入库仓库
            {
              compKey: 'compKey3',
              labelName: '领用部门：',
              codeField: 'deptName',
              component: () => import('@/components/org/commonInput'),
              oFields: 'AsId,AsText',
              type: 'inputText',
              isMust: true,
              span: 6
            },
            // 审核状态
            {
              compKey: 'compKey4',
              labelName: '领用人：',
              codeField: 'requisitioner',
              component: () => import('@/components/org/commonInput'),
              oFields: 'AsId,AsText',
              type: 'inputText',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey5',
              labelName: '领用用途：',
              codeField: 'requisitionUse',
              component: () => import('@/components/org/commonInput'),
              oFields: 'AsId,AsText',
              type: 'inputText',
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey6',
              labelName: '收货人：',
              codeField: 'receiver',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey7',
              labelName: '联系电话：',
              codeField: 'receiverPhone',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey8',
              labelName: '单据状态：',
              codeField: 'requisitionStatus',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: orgApis.findRequisitionStatus,
                defOptionFields: ['sendStatus', 'sendStatusName']
              },
              type: 'dropdownList',
              isMust: false,
              span: 6
            },
            {
              compKey: 'compKey9',
              labelName: '预算号：',
              codeField: 'budgetNumber',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false,
              span: 6
            }
          ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '查询',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey3',
          type: '',
          size: 'small',
          text: '导出',
          name: '',
          clickEvent: () => this.exportExcel1(),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: this.$t('sys.button.reset'),
          name: 'reset',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],

      formField: this.$utils.getFormField(this, {
        requisitionCode: '',
        warehouseId: '',
        deptName: '',
        requisitioner: '',
        requisitionUse: '',
        receiver: '',
        receiverPhone: '',
        requisitionStatus: '',
        budgetNumber: ''
      })
    }
  },
  mounted() {
    this.queryTable(1)
    // this.$refs.multipleTable.list = [
    //   {
    //     index: 1,
    //   },
    // ];
  },
  methods: {
    close(type) {
      this.editPopupsVisible = type
    },
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
      console.log(this.editRowData, 'editRowData')
    },
    exportExcel1() {
      // 导出
      exportExcel(this.formField, orgApis.internalCheckExtele.APIUrl, orgApis.internalCheckExtele.ServiceCode, '内部领用单查询')
    }
  }
}
</script>

<style>
</style>
